package com.team.appinfo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.appinfo.entity.AppInfo;
import com.team.appinfo.entity.AppInfoConstant;
import com.team.appinfo.entity.AppInfoTiaoJian;
import com.team.appinfo.mapper.AppInfoMapper;
import com.team.appinfo.mapper.AppVersionMapper;
import com.team.appinfo.service.AppinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class AppinfoServiceImpl implements AppinfoService{
    @Autowired
    private AppInfoMapper appInfoMapper;

    @Autowired
    private AppVersionMapper appVersionMapper;

    @Override
    public PageInfo<AppInfoConstant> getAppinfoAll(AppInfoTiaoJian appInfoTiaoJian) {
        PageHelper.startPage(appInfoTiaoJian.getPage(),appInfoTiaoJian.getPageSize());
        List<AppInfoConstant> list = this.appInfoMapper.getAppinfoAll(appInfoTiaoJian);
        PageInfo<AppInfoConstant>pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int addAppInfo(AppInfo appInfo) {
        return  this.appInfoMapper.insertSelective(appInfo);
    }

    @Override
    public AppInfoConstant getOneAppInfo(Long id) {
        return this.appInfoMapper.getOneAppInfo(id);
    }

    @Override
    public int updateAppInfo(AppInfoConstant appInfoConstant) {
        return this.appInfoMapper.updateAppInfoById(appInfoConstant);
    }

    @Transactional
    public void deleteAppInfoByAppId(Long id) {

        this.appVersionMapper.deleteVersionById(id);
        this.appInfoMapper.deleteByPrimaryKey(id);


    }

    @Override  //管理员查询所有待审核的app
    public PageInfo<AppInfoConstant> getAdminAppInfo(AppInfoTiaoJian appInfoTiaoJian) {
        PageHelper.startPage(appInfoTiaoJian.getPage(),appInfoTiaoJian.getPageSize());
        List<AppInfoConstant> list = this.appInfoMapper.getAdminAppInfo(appInfoTiaoJian);
        PageInfo<AppInfoConstant>pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public AppInfoConstant goAppInfoCheck(Long id) {
        return this.appInfoMapper.selectAdminByPrimaryKey(id);
    }

    @Override
    public int xiugaiAppInfoZhuangtai(Long status, Long id) {
        AppInfo appInfo=new AppInfo();
        appInfo.setStatus(status);
        appInfo.setId(id);
        return this.appInfoMapper.updateByPrimaryKeySelective(appInfo);
    }


}
